A program module includes source code for part or all of a computer program. A compiler may be used to produce an object code file from a program module. The object code files from different program modules may be linked together into an executable file for the program. The executable form of a multithreaded program includes multiple threads. A thread is a logically independent part of a computer program and can therefore be executed in parallel with other threads.
In a multiprocessor computer system, the operating system is generally responsible for distributing threads to the various processors for execution. Such thread distribution or scheduling may be performed periodically, for instance, once every second or so.
One conventional technique for distributing threads amongst multiple processors is depicted in FIG. 1. After grabbing 102 a read lock on the thread list, the technique starts 104 at the beginning of the thread list and at a starting processor number. The starting processor number may be the same each time, or it may be varied. The current thread is assigned 106 to the current processor. The current position in the thread list and the current processor number are incremented 110, and the current thread is continued to be assigned 106, until the last thread is assigned 108. After the last thread is assigned, the distribution of threads is complete and the read lock on the thread list is released 112.
The conventional technique discussed above has various disadvantages. In particular, in certain circumstances, the thread scheduling may be undesirably non-uniform. In other words, the distribution of threads to processors may result in a distribution that is substantially unfair to some threads.
It is desirable to improve methods and apparatus for computers and software. In particular, it is desirable to improve methods and apparatus for distributing threads to processors of a multiprocessor computer system.